package enums;

import headbean.ExcelHeadMapInterface;
import headbean.NameAndFactoryDemo;
import headbean.StudentDemo;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 表头flag枚举，映射flag与对应的实体类型；主要是可以根据flag找到对应实体类型。
 *
 * @author feng
 */
@Getter
@AllArgsConstructor
public enum ExcelHeadBeanFlagEnum {

    NAME_AND_FACTORY_DEMO("NameAndFactoryDemo", NameAndFactoryDemo.class),
    STUDENT_DEMO("StudentDemo", StudentDemo.class)
    ;

    private final String flag;
    private final Class<? extends ExcelHeadMapInterface> headClass;

    public static Class<? extends ExcelHeadMapInterface> getHeadClass(String flag) {
        return Arrays.stream(values()).
                filter(bean -> bean.getFlag().equals(flag))
                .findFirst()
                .orElseThrow(RuntimeException::new)
                .getHeadClass();
    }
}
